package jvm.classloader;
//静态执行的顺序是从上到下
public class Test6 {
    public static void main(String[] args) {
        //单例模式Singleton的构造方法是私有的，因此不能通过new创建对象
        //Singleton singleton = new Singleton();会报错
        Singleton singleton = Singleton.getInstance();
        System.out.println("counter1:"+Singleton.counter1);
        System.out.println("counter2:"+Singleton.counter2);
        System.out.println("counter3:"+singleton.counter3);


    }
}
class Singleton { //饿汉式
    public static int counter1;
    private static Singleton singleton = new Singleton();
    private Singleton() {
        counter1++;
        counter2++;
        counter3++;
    }
    public static int counter2 = 0;
    public int counter3 = 0;

    public static Singleton getInstance(){
        return singleton;
    }

}
